<%@ page import="java.util.List" %>
<%@ page import="com.hxzy.bean.HandSet" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 9/18
  Time: 15:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    //  http://ip:端口号/项目名/
    String contextPath = request.getContextPath();//得到项目路径
    int serverPort = request.getServerPort(); //得到端口号
    String serverName = request.getServerName();//得到服务器主机名
    String scheme = request.getScheme();
    String basePath = scheme + "://" + serverName + ":" + serverPort + contextPath;
    session.setAttribute("basePath",basePath);
%>
<html>
<head>
    <title>起始页</title>
    <link rel="stylesheet" href="static/bootstrap/css/bootstrap.css"/>

    <script type="text/javascript" src="static/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="static/bootstrap/js/bootstrap.min.js"></script>
    <style>
        th{
            text-align: center;
        }
    </style>
    <script>
        $(function(){
            console.log('浏览器加载完成======')
            $(".remove").click(function(){
                if (confirm('确定删除吗?')) {
                    //$(this) this指触发当前单击事件的dom对象
                    //$(this) 指将dom对象转换为jquery对象
                    //parent() 得到触发当前单击按钮对象的父级节点   <td>
                    //find(':hidden') 在td节点中找隐藏域的子节点
                    //val(): 获取隐藏域的value值
                    var hsId = $(this).parent().find(":hidden").val();
                    console.log("当前被删除的编号为：" + hsId);
                    window.location.href = "<%=basePath%>/remove?hsId=" + hsId;
                }
            });
        });
    </script>
</head>
<body>
    <div class="container">
        <table class="table table-bordered table-striped table-hover">
            <caption>
                <h1 class="text-center">手机信息</h1>
            </caption>
            <thead>
                <tr>
                    <th>品牌型号</th>
                    <th>参考报价</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody class="text-center">
                <%--<tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>--%>

                <%
                    //从request作用域中获取数据
                    Object handSets = request.getAttribute("handSets");
                    if (handSets != null) {
                        List<HandSet> list = (List<HandSet>) handSets;
                        for (HandSet handSet : list) {
                            out.println("\t\t\t\t<tr>");

                            out.print("\t\t\t\t\t<td>"+handSet.getNameType()+"</td>");
                            out.print("\t\t\t\t\t<td>"+handSet.getPrice()+"</td>");
                            out.print("\t\t\t\t\t<td>" +
                                    "<input type='hidden' value='"+handSet.getHsId()+"' />" +
                                    "<a href='detail?hsId="+handSet.getHsId()+"'>详情</a>" +
                                    " <a class='remove' href='javascript:void(0)'>删除</a>" +
                                    "</td>");

                            out.println("\t\t\t\t</tr>");
                        }
                    }
                %>
            </tbody>
        </table>
    </div>
</body>
</html>
